package cc.owoo.godpen.network.reptile;

/**
 * 页面下标
 * Created by nimensei
 * 2022-03-22 上午 01:58
 **/
public class PageIndex {
    private final String left;// 前缀
    private final String right;// 后缀

    public PageIndex(String express) {
        int index = 0;
        do {
            index = express.indexOf('$', index);
            if (index == -1 || index == express.length())
                throw new IllegalArgumentException("未找到$i的位置");
        } while (express.charAt(index + 1) != 'i');
        left = express.substring(0, index);
        right = express.substring(index + 2);
    }

    /**
     * 获取下标
     *
     * @param i 下标
     * @return 生成的字符串
     */
    public String get(int i) {
        return get(String.valueOf(i));
    }

    /**
     * 获取下标
     *
     * @param i 下标
     * @return 生成的字符串
     */
    public String get(String i) {
        return left + i + right;
    }

    /**
     * 获取前缀
     *
     * @return 前缀
     */
    public String getLeft() {
        return left;
    }

    /**
     * 获取后缀
     *
     * @return 后缀
     */
    public String getRight() {
        return right;
    }
}
